<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/common/header.jsp"%>
<c:set var="path" value="..${ctx}/define/actionunit"/>

<div class="pageContent" >
	<div class="panelBar">
		<ul class="toolBar">
			<li><a class="add" onclick="addunit('search','添加查询操作单元');" title="添加查询操作单元"><span>添加查询操作单元</span></a><br /><br /></li>
			<li class="line">line</li>
			<li><a class="add" onclick="addunit('update','添加更新操作单元');" title="添加更新操作单元"><span>添加更新操作单元</span></a><br /><br /></li>
			<li class="line">line</li>
			<li><a class="add" onclick="addunit('define','添加自定义操作单元');" title="添加自定义操作单元"><span>添加自定义操作单元</span></a><br /><br /></li>
			<li class="line">line</li>
			<li><a class="edit" onclick="modifyActionUnit();" title="修改操作单元" ><span>修改</span></a></li>
			<li class="line">line</li>
			<li><a class="edit" onclick="saveAllActionUnit();" title="保存所有单元"><span>保存</span></a></li>
			<li class="line">line</li>
			<li><a class="delete" onclick="deleteActionUnit();"><span>删除</span></a></li>
		</ul>
	</div>

	<div class="pageHeader">
		<form onsubmit="return navTabSearch(this);" action="${path}/search.html" method="post">
		<div class="searchBar">
			<table class="searchContent">
				<tr>
					<td>操作分类：</td>
					<td>
						<select class="combox" name="sort" >
							<option value="all">所有操作</option>
							<c:if test="${! empty sorts }">
							<c:forEach var="vo" items="${sorts}">
								<option value="${vo}"  <c:if test="${vo == sort}">selected="selected"</c:if> >${vo}</option>
							</c:forEach>
							</c:if>
						</select>
					</td>
					<td>操作名称：</td>
					<td>
						<input type="text" id="actionName" name="actionName" value="${actionName}" />
					</td>
					<td>
						<div class="buttonActive"><div class="buttonContent"><button type="submit">检索</button></div></div>
					</td>
				</tr>
			</table>
		</div>
		</form>
	</div>

	<table class="table" width="100%" layoutH="138">
		<thead>
			<tr>
				<th width="160">操作单元名称</th>
				<th width="80">分类</th>
				<th width="240">描述</th>
			</tr>

		</thead>
			<tbody>
			<c:if test="${! empty list}">
			<c:forEach var="vo" items="${list}">
			<c:set var="data" value="${vo.value}" />
			<tr target="params" rel="${data.actionType},${data.name}" class="base_define_action_unit_list_tr">
				<td>${data.name}</td>
				<td>${data.sort}</td>
				<td>${data.description}</td>
			</tr>
			</c:forEach>
			</c:if>
		</tbody>
	</table>

</div>

<script type="text/javascript">
/**
 * dialog上的表单提交回调函数
 * 服务器转回navTabId，可以重新载入指定的navTab. statusCode=DWZ.statusCode.ok表示操作成功, 自动关闭当前dialog
 * form提交后返回json数据结构,json格式和navTabAjaxDone一致
 */
function dialogAjaxDone(json){
	DWZ.ajaxDone(json);
	if (json.statusCode == DWZ.statusCode.ok){
		// alert(json.callbackType);
		if(json.callbackType){
			navTab.reload("${path}/paging.html?tableName=bs_role&jsp=base/power/role/role_list");//刷新
			setTimeout(function(){$.pdialog.closeCurrent();}, 100);
		}
	}
}

function addunit(action,title) {
	var url = "${path}/add.html?action=" + action;
	if(action == "search"){
		$.pdialog.open(url, "base_define_action_unit_add", title,{width:860,height:600,mask:true,maxable:false,resizable:false});
	} else if(action == "update"){
		$.pdialog.open(url, "base_define_action_unit_add", title,{width:800,height:500,mask:true,maxable:false,resizable:true});
	} else if(action == "define"){
		$.pdialog.open(url, "base_define_action_unit_add", title,{width:860,height:460,mask:true,maxable:false,resizable:false});
	}
	// var url = "${path}/add.html";
	// navTab.openTab("base_define_action_unit_add", url, { title:title, fresh:false, data:{action:action} });
}

function modifyActionUnit(){
	var rel = '';
	$('.base_define_action_unit_list_tr').each(function(){
		// alert($(this).attr('rel'));
		if($(this).hasClass("selected")){
			rel = $(this).attr('rel');
		}
	});
	if(rel==''){
		alertMsg.warn('请先选择一条数据！');
	}else{
		var title = "更新操作单元";
		// var url = "${path}/get.html";
		// navTab.openTab("base_define_modify_actionunit", url, { title:title, fresh:false, data:{name:rel} });
		var arr = rel.split(","); //字符分割 
		// action = decodeURIComponent(action);
		var action = encodeURI(encodeURI(arr[1]));
		var url = "${path}/get.html?name=" + action;
		// alert(arr[0]);
		if(arr[0] == "search"){
			$.pdialog.open(url, "base_define_action_unit_add", title,{width:860,height:600,mask:true,maxable:false,resizable:false});
		} else if(arr[0] == "update"){
			$.pdialog.open(url, "base_define_action_unit_mod", title,{width:800,height:500,mask:true,maxable:false,resizable:true});
		} else if(arr[0] == "define"){
			$.pdialog.open(url, "base_define_action_unit_add", title,{width:860,height:460,mask:true,maxable:false,resizable:false});
		}
		
	}
}

function saveAllActionUnit(){
	var url = "${path}/saveAll.html";
	$.ajax({
		type: "post", url: url,
		success: function(json){
			var result = JSON.parse(json); 
			if (result.statusCode == DWZ.statusCode.ok){
				alertMsg.correct(result.message);
			}
		},
		error: function(){
			alertMsg.error('系统错误，请联系管理员！');
		}
	});
}

function deleteActionUnit(){
	var rel = '';
	$('.base_define_action_unit_list_tr').each(function(){
		if($(this).hasClass("selected")){
			rel = $(this).attr('rel');
		}
	});
	if(rel==''){
		alertMsg.warn('请先选择一条数据！');
	}else{
		alertMsg.confirm("确定要删除吗?", {
			okCall: function(){
				var arr = rel.split(","); //字符分割 
				var url = "${path}/delete.html?type=action&id=" + arr[1];
				$.ajax({
					type: "post", url: url,
					success: function(json){
						alertMsg.correct(json.msg);
						var url = "${path}/list.html";
						navTab.reload(url);
					},
					error: function(){
						alertMsg.error('系统错误，请联系管理员！');
					}
				});
			}
		});
	}
}

</script>


